<template>
	<view>
		<!-- 搜索区域 -->
		<view class="search-box">
			<view class="call-box u-m-t-2">
				<u-search placeholder="请输入客户组名称" v-model="key" @change="searchKey" style="width: 100%;"></u-search>
			</view>
			<!-- 搜索结果 -->
			<view class="search-list">
				<view class="u-flex u-justify-content u-p-20" v-if="loading">
					<u-loading mode="flower"></u-loading><text class="u-tips-color u-m-l-10">搜索中...</text>
				</view>
				<view v-if="searchList.length > 0">
					<view class="u-m-l-30 u-m-t-10 u-m-b-10"><text class="u-tips-color u-font-24">{{searchList.length}}条搜索结果</text></view>
					<u-cell-group>
						<u-cell-item 
							v-for="(item,index) in searchList"
							:key="index"
							:title="item.name" 
							@click="getDepartment(item)"
							>
						</u-cell-item>
					</u-cell-group>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loading: false,
				pageIndex: 1,
				pageSize: 20,
				// 选择地区
				cityshow: false,
				// 搜索客户组
				searchList: [],
				key: '',
				// 
			}
		},
		onLoad() {
			
		},
		onReachBottom() {
			
		},
		methods: {
			searchKey(key){
				this.key = key
				this.getEnterpriseList()
			},
			getEnterpriseList(){
				this.$u.post('/Enterprise/List',{
					"pageIndex": this.pageIndex,
					"pageSize": this.pageSize,
					"key": this.key
				}).then((res)=>{
					this.searchList = res.rows
				})
			},
			getDepartment(item){
				uni.navigateTo({
					url: '/pages/my/enterprises/binding/department/department?id='+item.id
				})
				// if(item.parentid == 0){
				// 	this.$u.post('/Enterprise/List',{
				// 		"pageIndex": this.pageIndex,
				// 		"pageSize": this.pageSize,
				// 		"key": this.key,
				// 		"parentId": item.id
				// 	}).then((res)=>{
				// 		this.searchList = res.rows
				// 	})
				// }else{
					
				// }
			},
			// getSelectCity(arr) { //城市选择回调函数
			// 	console.log(arr)
			// 	this.cityshow = false
			// 	// this.selectArea = '';
			// 	let cityidArr = [];
			// 	let getArr = arr.filter(n => n.id != 0)
			// 	let areaname = '';
			// 	getArr.forEach((item, index) => {
			// 		if (index == getArr.length - 1) {
			// 			areaname += item.name
			// 		} else {
			// 			areaname += item.name + '-'
			// 		}
			// 		cityidArr.push(item.id);
			// 	});
			// 	if (cityidArr.length > 0)
			// 		// this.form.cityPath = cityidArr[cityidArr.length - 1];
			// 		this.form.cityPath = cityidArr.join(',');
			// 	if (areaname)
			// 		// this.form.cityName = areaname;
			// 		this.form.cityName = areaname.split("-")[areaname.split("-").length - 1]
			// },
			back(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.call-box {
		display: flex;
		align-items: center;
		background: #fff;
		padding: 30rpx;
	}
	.binding{
		min-height: 100vh;
		background-color: #fff;
	}
	.container{
		background-color: #fff;
		padding: 0 30rpx;
	}
	.btn-box{
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 16rpx 30rpx;
		border-radius: 8rpx;
		position: relative;
		transition: all 0.3s linear;
		border: 1px solid #fff;
		border-color: #fcbd71;
		background-color: #fdf6ec;
	}
</style>
